from app.feature_toggle import features


class APSchedulerConfig:
    JOBS = [{
        'id': 'run_at_09_10',
        'func': 'app.schedule_task:run_at_09_10',
        'misfire_grace_time': 3600,
        'trigger': 'cron',
        'day_of_week': 'mon-fri',
        'hour': '9',
        'minute': '10'
    }]

    if features('new_stock').active:
        JOBS.append({
            'id': 'apply_new_stocks',
            'func': 'app.schedule_task:apply_new_stocks',
            'misfire_grace_time': 900,
            'trigger': 'cron',
            'day_of_week': 'mon-fri',
            'hour': '14',
            'minute': '45'
        })

    if features('reverse_repo').active:
        JOBS.append({
            'id': 'reverse_repo',
            'func': 'app.schedule_task:reverse_repo',
            'misfire_grace_time': 600,
            'trigger': 'cron',
            'day_of_week': 'mon-fri',
            'hour': '15',
            'minute': '5-20',
            'second': '0'
        })

    SCHEDULER_JOB_DEFAULTS = {
        'coalesce': True,
        'max_instances': 1
    }

    SCHEDULER_API_ENABLED = True
    SCHEDULER_VIEWS_ENABLED = True
    SCHEDULER_TIMEZONE = "Asia/Shanghai"
